#include "AutoFind.h"

/// 几种不同的测试类型项的demo延时
/// root 要在退出的时候删除
/// 下面三种适用于可以在配置文件写指令的，其它需要单独写逻辑过程的单独再加
/// 简单测试,一条自动结束的指令
void TestSimple(cJSON *root){

    log_info("here...");
    std::string key = std::string(cJSON_GetStringValue(cJSON_GetObjectItem(root, "key")));
    testStatus[key] = true;
    while (testStatus[key]){
        std::this_thread::sleep_for(std::chrono::seconds(5));
        cJSON_ReplaceItemInObject(root,"output", cJSON_CreateString("sadsadsadsdsd"));
        SEND_PACK(root);
        testStatus[key] = false;
    }
    cJSON_ReplaceItemInObject(root,"output",cJSON_CreateTrue());
    SEND_PACK(root);

    testStatus.erase(key);
    cJSON_Delete(root);
}

/// 中断测试
void TestSimpleV1(cJSON *root){

    log_info("here...V1 i");
    std::string key = std::string(cJSON_GetStringValue(cJSON_GetObjectItem(root, "key")));
    testStatus[key] = true;
    while (testStatus[key]){

    }
    cJSON_ReplaceItemInObject(root,"output",cJSON_CreateTrue());
    SEND_PACK(root);
    log_info("here...V1");
    testStatus.erase(key);
    cJSON_Delete(root);
}

/// 持续测试
void TestSimpleV2(cJSON *root){

    int i=0;
    log_info("here...V2 i");
    std::string key = std::string(cJSON_GetStringValue(cJSON_GetObjectItem(root, "key")));
    testStatus[key] = true;
    while (testStatus[key]){
        cJSON_ReplaceItemInObject(root,"output", cJSON_CreateNumber(i++));
        SEND_PACK(root);
        std::this_thread::sleep_for(std::chrono::seconds(2));
    }
    cJSON_ReplaceItemInObject(root,"output",cJSON_CreateTrue());
    SEND_PACK(root);
    log_info("here...V2");
    testStatus.erase(key);
    cJSON_Delete(root);
}
